# -*- coding: UTF-8 -*-
from abaqus import *
from odbAccess import *
from abaqusConstants import *
import regionToolset

# test:
# importPart("e:\Desktop\impact_MU\stackShell\my1_0.odb",'importTest',30)
def importPart(str_path,model_name,totalNum):
    '''
    功能：导入部件并赋予截面属性，生成装配体

    参数：
    str_path: odb文件的路径
    model_name: Model的名称
    totalNum: 要布置的开口壳总数量
    '''

    currModel = mdb.Model(model_name)

    import material
    mat01_name = 'AISI 1005 Steel'
    mat01 = currModel.Material(name = mat01_name)
    mat01.Density(table = ((7.8e-9, ), ))
    mat01.Elastic(table = ((200E3 , 0.29), ))

    import section
    shellSection = currModel.HomogeneousShellSection(name='shellSection', material=mat01_name, thicknessType=UNIFORM, thickness=1.0)

    odb_import = openOdb(path=str_path, readOnly=False)
    currAssembly = currModel.rootAssembly
    for i in range(totalNum):
        newInstanceName = 'openShell-'+str(i)
        currModel.PartFromOdb(name = newInstanceName, instance = newInstanceName.upper(), odb=odb_import, shape=DEFORMED, step=0, frame=20)
        currPart = currModel.parts[newInstanceName]
        currPart.SectionAssignment(region=(currPart.elements,), sectionName='shellSection', offset=0.0, offsetType=MIDDLE_SURFACE, offsetField='', thicknessAssignment=FROM_SECTION)
        currAssembly.Instance(name = newInstanceName, part = currPart, dependent = OFF)
        
    odb_import.close()